</div>
</div>
</div>
<div id="footer">
<br />

<div align="center">
&copy; 2012 - <a href="http://fedobe.com" target="_blank">Fedobe</a> - Page rendered in <span style="color: #0073EA;">{elapsed_time}</span> seconds. <span class="text-info">Beta Version - v1.2.1</span>
<br /><br />
</div>
</div>
<div>
	
<div id="attendancemodel" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
    <h4 id="myModalLabel" style="text-align: center">My Attendance for <?= date('d-M-Y')?></h4>
  </div>
  <div class="modal-body">
    <p>
	<?php $server_time = $this->common_model->get_server_time();?>
     <input type="hidden" value="<?= $server_time?>" id="server_time" />   
    <table width="100%">
	<tr>
	<th>Entry Time</th>	
	<th>Lunch Time In</th>	
	<th>Lunch Time Out</th>			
	<th>Exit Time</th>	
	</tr>
  <tr align="center">
    <td>
	<div class="text-info" style="display:none; " id="show_entry_time"></div>
	<input type="hidden" value="" id="start_time_attendance" />   
    <input type="button" value="Entry Time" name="attendance_entry" id="attendance_entry" class="btn btn-primary btn btn-mini " />
   </td>
  	
	<td>
		<input type="button" value="Entry Time" name="lunch_in" id="lunch_in" class="btn btn-primary btn btn-mini" />
	    <div class="text-info" style="display:none;" id="show_lunch_in_time"></div>

	</td>
	<td>
		<input type="button" value="Exit Time" name="lunch_out" id="lunch_out" class="btn btn-warning btn btn-mini" />
    	<div class="text-warning" style="display:none;" id="show_lunch_out_time"></div>
	</td>
	
    <td>
	<input type="button" value="Exit Time" name="attendance_exit" id="attendance_exit" class="btn btn-mini btn-warning" />
    <div class="text-warning" style="display:none;" id="show_exit_time"></div>
    </td>
  </tr>
</table>
<br />
<table class="table" width="100%">
	<tr>
	<td width="40%" class="drink_heading" valign="middle">
	What you are gonna take today ?
	</td>
	<?php 
		$drinks = $this->common_model->get_drinks();	
	?>	
	<td width="20%"><input type="radio" name="drink" class="drink" value="tea" <?php if($drinks == 'tea'){echo 'checked';} ?> />&nbsp;<img src="<?= $this->config->base_url(); ?>assets/images/tea.png" ></td>
	<td width="20%"><input type="radio" name="drink" class="drink" value="coffee" <?php if($drinks == 'coffee'){echo 'checked';} ?> />&nbsp;<img src="<?= $this->config->base_url(); ?>assets/images/coffee.png" ></td>
	<td width="20%"><input type="radio" name="drink" class="drink" value="soup" <?php if($drinks == 'soup'){echo 'checked';} ?> />&nbsp;<img src="<?= $this->config->base_url(); ?>assets/images/soup.png" ></td>	
	</tr>
</table>
	<div class="modal-footer">
	<div style="float: left">    
	<span id="working_hr_time" class="text-danger" style="font-size: 18px"></span>	&nbsp; <!--<a href="javascript:void(0)" class="text-error" onclick="working_hr()"> <i class=" icon-refresh"></i></a>-->
   </div>
			<input type="button" class="btn btn-small btn-success" value="Take today" name="drinks" id="drinks"/>
					</div>
   </p>
  </div>
  
</div>
<script type="text/javascript" >
	$(document).ready(function() {		
			
$.post('<?= site_url('user/attendance/check_entry_time');?>', function(data){	
	  if(data){	  
	  	$('#attendance_entry').hide()		
		$('#show_entry_time').show()
		$('#show_entry_time').append(data);
		$('#start_time_attendance').val(data);	
	
		var current_time  = $("#server_time").val();		
		var dif = diff(data,current_time);		
		$('#working_hr_time').append(dif);			
			
	  }else {
		$('#lunch_in').hide()
	  }
});	

//lunch time check
$.post('<?= site_url('user/attendance/check_lunch_in_time');?>', function(data){
	
	  if(data){	
	 	 
		$('#lunch_in').hide()		
		$('#show_lunch_in_time').show()
		$('#show_lunch_in_time').html(data)			
	  }	
	  else {
		$('#lunch_out').hide()  
	  }
});	

$.post('<?= site_url('user/attendance/check_lunch_out_time');?>', function(data){
	
	  if(data){	
	 	 
		$('#lunch_out').hide()		
		$('#show_lunch_out_time').show()
		$('#show_lunch_out_time').html(data)				
	  }	
	  else {
		$('#attendance_exit').hide()  
	  }
});	

$.post('<?= site_url('user/attendance/check_exit_time');?>', function(data){
				
	  
	  if(data){	
	 	 
		$('#attendance_exit').hide()		
		$('#show_exit_time').show()
		$('#show_exit_time').html(data)		
		
				
	  }	
	  else {
		//$('#attendance_exit').hide()  
	  }
});	


});


// Entry time for attendance
$("#attendance_entry").click(function(){			
var server_time = $("#server_time").val();
 var count = 0;
//alert(server_time)
 $.post('<?= site_url('user/attendance/insert_entry_time');?>',{time : server_time}, function(data) {
	 alert(data)	 
	 $('#myModal').modal('hide')
	 $('#attendance_entry').hide()	
	 $('#show_entry_time').show()	
location.reload();
	 
});
})

// exit time for attendance
$("#attendance_exit").click(function(){			
var server_time = $("#server_time").val();

 $.post('<?= site_url('user/attendance/insert_exit_time');?>',{time : server_time}, function(data) {	 
	 if(data){
		alert(data)
		 $.post('<?= site_url('user/attendance/insert_daily_attendance_sheet');?>', function(msg) { 		 	
			 $('#myModal').modal('hide')
			 $('#attendance_exit').hide()	
			 location.reload();	
		 }); 	 
	 	}	 
	});
})


// lunch in time for attendance
$("#lunch_in").click(function(){			
var server_time = $("#server_time").val();
//alert(server_time)

 $.post('<?= site_url('user/attendance/insert_lunch_in_time');?>',{time : server_time}, function(data) {	 
	 $('#myModal').modal('hide')
	 $('#lunch_in').hide()	
	 location.reload();
 
});
})

// lunch out time for attendance
$("#lunch_out").click(function(){			
var server_time = $("#server_time").val();
//alert(server_time)

 $.post('<?= site_url('user/attendance/insert_lunch_out_time');?>',{time : server_time}, function(data) {	 
	 $('#myModal').modal('hide')
	 $('#lunch_out').hide()	
	 location.reload();
	 
});
})


$("#drinks").click(function(){	
var drink = $(".drink:checked").val();
$.post('<?= site_url('user/attendance/check_id');?>', function(data){	
	  if(data){
 		var id = data;	
		$.post('<?= site_url('user/user/insert_drinks');?>',{id : id,drink : drink}, function(drinks_selected) {	 
	 		alert("Your" + " " + drink + " " + "is gonna be ready for today !");
							$('#myModal').modal('hide')
	 								
		});			
	  }	
	 
});
})

function diff(start, end) {
    start = start.split(":");
    end = end.split(":");
    var startDate = new Date(0, 0, 0, start[0], start[1], 0);
    var endDate = new Date(0, 0, 0, end[0], end[1], 0);
    var diff = endDate.getTime() - startDate.getTime();
    var hours = Math.floor(diff / 1000 / 60 / 60);
    diff -= hours * 1000 * 60 * 60;
    var minutes = Math.floor(diff / 1000 / 60);    
    return (hours < 9 ? "0" : "") + hours + ":" + (minutes < 9 ? "0" : "") + minutes;
}
</script>
	
</div>
</div>
</body>
</html>
